package cn.tedu.ivos.geofence.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.base.response.StatusCode;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceParam;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/geofence")
public class GeofenceController {
    @Autowired
    private GeofenceService geofenceService;

    @GetMapping("/select")
    public JsonResult selectGeofenceTab(GeofenceQuery geofenceQuery) {
        log.debug("开始查询围栏信息"+geofenceQuery);
        List<GeofenceVO> list = geofenceService.selectGeofenceTab(geofenceQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("/add")
    public JsonResult addGeofence(GeofenceParam geofenceParam) {
        log.debug("开始添加围栏信息"+geofenceParam);
        int row =geofenceService.addGeofenceTab(geofenceParam);
        if (row == 1) {
            return JsonResult.ok();
        }
        return new JsonResult(StatusCode.OPERATION_FAILED,"添加失败");
    }
    @PostMapping("/delete/{id}")
    public JsonResult deleteGeofence(@PathVariable Long id) {
        log.debug("开始删除围栏信息"+id);
        int row =geofenceService.deleteGeofenceTab(id);
        log.debug("删除围栏信息"+row);
        if (row == 1) {
            return JsonResult.ok();
        }else if (row==-1) {
            return new JsonResult(StatusCode.EXISTS_BINDVEHICLE,"删除失败");
        }
        return new JsonResult(StatusCode.OPERATION_FAILED,"删除失败");
    }

}
